from collections import OrderedDict

from django.shortcuts import render
# from fdfs_client.client import Fdfs_client

# Create your views here.
from django.views import View

from apps.contents.models import ContentCategory
from apps.contents.utils import get_categories
from apps.goods.models import GoodsChannel


class IndexView(View):
    def get(self,request):

        categories = get_categories()
        # 广告数据
        contents = {}
        content_categories = ContentCategory.objects.all()
        for cat in content_categories:
            contents[cat.key] = cat.content_set.filter(status=True).order_by('sequence')

        # 渲染模板的上下文
        context = {
            'categories': categories,
            'contents':contents,
        }
        return render(request, 'index.html', context)


# from fdfs_client.client import Fdfs_client
# client = Fdfs_client('utils/fastdfs/client.conf')
# client.upload_by_filename('/home/python/Desktop/image/IMG_8871.JPG')


# group1/M00/00/00/wKighV0xm9OAeZjjAAFCYlibLTc123.JPG
